<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>预约看房设置</span>
      </div>
      <div>
        <el-form ref="form" :model="form" :rules="rules" label-width="auto">
          <!-- <el-row :gutter="18" class="mb8">
            <el-col :span="9">
              <el-form-item label="看房押金" prop="securityPrice">
                <el-input v-model="form.securityPrice" placeholder="请输入看房押金" size="small" />
              </el-form-item>
            </el-col>
          </el-row> -->
          <el-row :gutter="18" class="mb8">
            <el-col :span="9">
              <el-form-item label="看房审核开关" prop="appointmentAudit">
                <el-radio-group v-model="form.appointmentAudit">
                  <el-radio v-for="(item, index) in appointment" :key="index" :label="item.value" :value="item.value">
                    {{ item.label }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- <el-row :gutter="18" class="mb8">
            <el-col :span="9">
              <el-form-item label="退看房押金审核开关" prop="securityPriceRefundAudit">
                <el-radio-group v-model="form.securityPriceRefundAudit">
                  <el-radio v-for="(item, index) in securityPriceRefund" :key="index" :label="item.value"
                    :value="item.value">
                    {{ item.label }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row> -->
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import { listAppointmentViewSetting, addAppointmentViewSetting, updateAppointmentViewSetting } from "@/api/mall/appointmentViewSetting";

export default {
  name: "AppointmentViewSetting",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 预约看房设置表格数据
      appointmentViewSettingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        securityPrice: undefined,
        appointmentAudit: undefined,
        securityPriceRefundAudit: undefined
      },
      // 房审核开关
      appointment: [
        {
          value: '0',
          label: '不需要'
        },
        {
          value: '1',
          label: '需要'
        }
      ],
      //退看房押金
      securityPriceRefund: [
        {
          value: '0',
          label: '不需要'
        },
        {
          value: '1',
          label: '需要'
        }
      ],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        securityPrice: [
          { required: true, message: '请填写看房押金', trigger: 'blur' },
          { pattern: /^[0-9|^\\.]/, message: '数值不能为负数' }
        ],
        appointmentAudit: [
          { required: true, message: '请选择房审核开关', trigger: 'blur' },
        ],
        securityPriceRefundAudit: [
          { required: true, message: '请选择退看房押金审核', trigger: 'blur' },
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询预约看房设置列表 */
    getList() {
      this.loading = true;
      listAppointmentViewSetting(this.queryParams).then(response => {
        this.form = response.rows[0];
        this.loading = false;
      });
    },

    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateAppointmentViewSetting(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addAppointmentViewSetting(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
  }
};
</script>